package web_wuyu.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloWorld
 */
//@WebServlet("/HelloWorld")

public class HelloWorld extends HttpServlet {
	//private static final long serialVersionUID = 1L;
    private String  message;
    /**
     * @see HttpServlet#HttpServlet()
     */
    /*public HelloWorld() {
    	super();
    	message="Hello World";
        // TODO Auto-generated constructor stub
    }*/
    public void init() throws ServletException{
    	message="Hello World";
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		//设置相应内容类型
		response.setContentType("text/html");
		//实际的逻辑在这里
		PrintWriter out=response.getWriter();
		out.println("<h1>"+message+"</h1>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
